using System;
using System.IO;
using Servlets.Attributes;
using Servlets.Http;
using System.Reflection;
using Servlets.Api;

namespace Servlets
{
	public class StaticFileServlet
	{
		public void GetStaticFile(IRequest request, IResponse response) {
			string filepath = Server.Server.STATIC_ROOT + request.Url;
			ResponseStream stream = response.OutputStream;
			response.SetProperty(HttpProperty.ContentType, ContentType.FromExtension(Path.GetExtension(filepath)).Value);
			byte[] content = File.ReadAllBytes(filepath);
			stream.Write(content);
		}
		
		public static MethodInfo StaticFileGetMethod() {
			Type type = typeof(StaticFileServlet);
			return type.GetMethod("GetStaticFile");
		}
	}
}

